
using System;
using System.Linq;
using Csla;
using Csla.Data;
using HousingInfo.DataLinQ;

namespace HousingInfo.Library
{ 
	public partial class SubTopicForumBOList : Csla.BusinessListBase<SubTopicForumBOList, SubTopicForumBO>
	{
        #region ham lay tat ca danh sach chu de 4Rum
        public static SubTopicForumBOList GetAllSubTopicForumBOList()
        {
            return DataPortal.Fetch<SubTopicForumBOList>();
        }
        #endregion
		#region Authorization Rules

		protected static void AddObjectAuthorizationRules()
		{
			//TODO: Define object-level authorization rules of SubTopicForumBOList
			//AuthorizationRules.AllowCreate(typeof(SubTopicForumBOList), "SubTopicForumBOListCreateGroup"));
			//AuthorizationRules.AllowEdit(typeof(SubTopicForumBOList), "SubTopicForumBOListEditGroup"));
			//AuthorizationRules.AllowDelete(typeof(SubTopicForumBOList), "SubTopicForumBOListDeleteGroup"));
		}
		#endregion //Authorization Rules

        #region Ham kiem tra tin con ton tai trong danh muc topic forum can xoa
        public static bool CheckCategoryInSubTopicForum(int cateID)
        {
            int count = 0;
            using (var mgr = ContextManager<HousingInfoDataContext>
                    .GetManager(Database.HousingInfoConnection))
            {
                count = mgr.DataContext.SubTopicForums.Count(n => n.CategoryID == cateID);
            }

            return (count > 0);
        }
        #endregion // end kiem tra khi xoa danh muc
        #region truy cap du lieu cua ham lay tat ca danh sach 
        [Transactional(TransactionalTypes.TransactionScope)]
        private void DataPortal_Fetch()
        {
            bool cancel = false;
            if (cancel) return;

            using (var mgr = ContextManager<HousingInfo.DataLinQ.HousingInfoDataContext>
                        .GetManager(Database.HousingInfoConnection))
            {
                RaiseListChangedEvents = false;

                this.AddRange(
                    from row in mgr.DataContext.SubTopicForums
                    select SubTopicForumBO.GetSubTopicForumBO(row.SubTopicForumID)
                );

                RaiseListChangedEvents = true;
            }//using
        }
        #endregion
        #region Ham lay chu de theo chuyen de trang chu de dien dan
        #region khai bao ham
        public static SubTopicForumBOList GetSubTopicForumBOList_ByID(int id)
        {
            return DataPortal.Fetch<SubTopicForumBOList>(new FilterCriteriaTopicForum_ByID(id));
        }
        #endregion

        #region khai bao bien
        private class FilterCriteriaTopicForum_ByID
        {
            public int idcategory;
            public FilterCriteriaTopicForum_ByID(int id)
            {
                this.idcategory = id;
            }
        }
        #endregion

        #region truy cap du lieu
        private void DataPortal_Fetch(FilterCriteriaTopicForum_ByID cretia)
        {
            bool cancel = false;
            if (cancel) return;

            using (var mgr = ContextManager<HousingInfo.DataLinQ.HousingInfoDataContext>
                        .GetManager(Database.HousingInfoConnection))
            {
                RaiseListChangedEvents = false;

                this.AddRange(
                    from row in mgr.DataContext.SubTopicForums
                    where row.CategoryID == cretia.idcategory
                    select SubTopicForumBO.GetSubTopicForumBO(row.SubTopicForumID)
                );

                RaiseListChangedEvents = true;
            }//using
        }
        #endregion
        #endregion
   
	}
}
